package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	UserId   int     `gorm:"type:int;not null;comment:'用户id'"`
	Details  string  `gorm:"type:varchar(30);not null;comment:'商品名称'"`
	Price    float64 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
	Quantity int     `gorm:"type:int;not null;comment:'数量'"`
}
type Order struct {
	gorm.Model
	UserId      int     `gorm:"type:int;not null;comment:'用户id'"`
	TotalAmount string  `gorm:"decimal(10,2);not null;comment:'订单金额'"`
	Price       float64 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
	OrderTime   int     `gorm:"type:date;not null;comment:'订单时间'"`
	OrderStatus int     `gorm:"type:tinyint(1);not null;comment:'订单状态'"`
}

type OrderItems struct {
	gorm.Model
	OrderID   int     `gorm:"type:int;not null;comment:'用户id'"`
	ProductID int     `gorm:"type:int;not null;comment:'用户id'"`
	Quantity  int     `gorm:"int;not null;comment:'商品数量'"`
	Price     float64 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
}

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(30);not null;comment:'账号'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
	Contact  string `gorm:"type:varchar(30);not null;comment:'用户联系方式'"`
}
type RealName struct {
	gorm.Model
	IDCard   string `gorm:"type:char(18);not null;comment:'身份证号'"`
	RealName string `gorm:"type:varchar(30);not null;comment:'真实姓名'"`
	UserId   int    `gorm:"type:int(10);not null;comment:'用户id'"`
}

func (u *User) GetUserInfo() error {
	return DB.Debug().Where("account =?", u.Account).Limit(1).Find(&u).Error
}

func (u *User) GetUserInfoById() error {
	return DB.Debug().Where("id =?", u.ID).Limit(1).Find(&u).Error
}

func (u *User) CreateUserInfo() error {
	return DB.Debug().Create(&u).Error
}

func (r *RealName) GetRealNameId() error {
	return DB.Debug().Where("user_id =?", r.UserId).Limit(1).Find(&r).Error
}

func (r *RealName) CreateRealName() error {
	return DB.Debug().Create(&r).Error
}

func (g *Goods) GetGoodsById() error {
	return DB.Where("id =?", g.ID).Limit(1).Find(&g).Error
}

func (g *Goods) CreateGoods() error {
	return DB.Create(&g).Error
}

func (u *User) GetUserByAccount() error {
	return DB.Where("account =?", u.Account).Limit(1).Find(&u).Error
}

func (u *User) GetUserById() error {
	return DB.Where("id  =?", u.ID).Limit(1).Find(&u).Error
}
func (u *User) CreateUser() error {
	return DB.Create(&u).Error
}
